<template>
	<view class="content">
		<view class="clock-top flexWrap">
			<view class="top-left flexWarpColumn">
				<view class="clock-tips flexWarpColumn">
					<image src="/static/index/task-title.png"></image>
					<text>签到可有机会领取好礼</text>
				</view>
				<view class="clock-btn" @tap="signin()" :class="{signed:is_signin==1}">{{is_signin==0?'立即签到':'已签到'}}</view>
			</view>
			<image src="/static/index/calendar-img.png" class="calendar-img"></image>
		</view>
		<view class="calendar-box">
			<view class="calendar-top">
				<view class="top-title">已连续打卡{{signin_num}}天</view>
				<view class="tips-box flexWrapNo">
					<view class="total">累计打卡{{total_signin_num}}天</view>
					<view>超过了{{ratio}}的店长</view>
				</view>
			</view>
			<wu-calendar @monthSwitch="getDate" :useToday="false" mode="multiple" :showMonth="false" color="#2CA522" :date="selected" :monthShowCurrentMonth="true"></wu-calendar>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				selected:[],
				is_signin:0,
				ratio:"",
				signin_num:0,
				total_signin_num:"",
				month:"",
				year:""
			};
		},
		onLoad() {
			this.getSignInfo();
		},
		methods:{
			getSignInfo(){
				this.$request.post(this.$api.signInfo, {
					store_id:uni.getStorageSync('store_id'),
					year:this.year,
					month:this.month
				}, {
					token:true
				}).then(res => {
					if (res.code==1) {
						let {
							data = {}
						} = res;
						this.is_signin=data.is_signin
						this.ratio=data.ratio
						this.signin_num=data.signin_num
						this.total_signin_num=data.total_signin_num
						for (let i in data.signin_list) {
							this.selected.push(data.signin_list[i].date)
						}
						this.selected=[...new Set(this.selected)]
						console.log(this.selected)
					}
				})
			},
			signin(){
				if(this.is_signin==1){
					return;
				}
				this.$request.post(this.$api.signin, {
					store_id:uni.getStorageSync('store_id')
				}, {
					token:true
				}).then(res => {
					if (res.code==1) {
						this.$tools.showToast('签到成功')
						this.getSignInfo();
					}
				})
			},
			getDate(e){
				console.log(e)
				this.year=e.year
				this.month=e.month
				this.getSignInfo();
			}
		}
	}
</script>

<style lang="scss">
	.content{
		padding: 34rpx;
	}
	.clock-top{
		.top-left{
			.clock-tips{
				font-size: 28rpx;
				font-family: PingFang SC-Medium, PingFang SC;
				font-weight: 500;
				color:#82819B;
				image{
					width: 280rpx;
					height: 40rpx;
					margin-bottom: 14rpx;
				}
			}
			.clock-btn{
				width: 208rpx;
				height: 72rpx;
				line-height: 72rpx;
				background: #38AAF4;
				border-radius: 16rpx 16rpx 16rpx 16rpx;
				font-size: 28rpx;
				font-family: PingFang SC-Medium, PingFang SC;
				font-weight: 500;
				color: #FFFFFF;
				margin-top: 38rpx;
				text-align: center;
			}
			.signed{
				background: #1D1C5C;
			}
		}
		.calendar-img{
			width: 298rpx;
			height: 298rpx;
		}
	}
	.calendar-box{
		.calendar-top{
			padding: 30rpx 26rpx;
			background: #1D1C5C;
			border-radius: 16rpx 16rpx 16rpx 16rpx;
			margin-bottom: 4rpx;
			.top-title{
				font-size: 36rpx;
				font-family: PingFang SC-Medium, PingFang SC;
				font-weight: 500;
				color: #FFFFFF;
			}
			.tips-box{
				font-size: 24rpx;
				font-family: PingFang SC-Regular, PingFang SC;
				font-weight: 400;
				color: #FFFFFF;
				margin-top: 16rpx;
				.total{
					font-size: 24rpx;
					font-family: PingFang SC-Regular, PingFang SC;
					font-weight: 400;
					color: #FFFFFF;
					height: 34rpx;
					line-height: 34rpx;
					background: #2CA522;
					border-radius: 16rpx 16rpx 16rpx 16rpx;
					padding: 0 12rpx;
					margin-right: 6rpx;
				}
			}
		}
	}
</style>
